package com.example.chenjun.myapplication.net;

import com.example.chenjun.myapplication.net.okhttp.OkHttpLoader;
import com.example.chenjun.myapplication.net.retrofit.RetrofitLoader;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;

public class NetController {
    private Map<String, String> params;
    private Map<String, String> headers;
    private String url;
    private String tag;
    private File file;
    private Map<String, File> files;
    private METHOD method;

    public enum METHOD{

        /**
         * post请求
         */
        POST,

        /**
         * get请求
         */
        GET;
    }

    public enum NET_TYPE{
        OKHTTP,

        RETROFIT;
    }

    public static NetController post(){
        return new NetController().setMethod(METHOD.POST);
    }

    public static NetController get(){
        return new NetController().setMethod(METHOD.GET);
    }

    private NetController(){
        params = new HashMap<>();
        headers = new HashMap<>();
        files = new HashMap<>();
    }

    public METHOD getMethod() {
        return method;
    }

    public NetController setMethod(METHOD method) {
        this.method = method;
        return this;
    }

    public NetController addParam(String key, String value){
        params.put(key, value);
        return this;
    }

    public NetController addHeader(String key, String header){
        headers.put(key, header);
        return this;
    }

    public NetController setUrl(String url){
        this.url = url;
        return this;
    }

    public NetController setTag(String tag) {
        this.tag = tag;
        return this;
    }

    public NetController setFile(File file){
        this.file = file;
        return this;
    }

    public NetController putFile(String key, File file){
        files.put(key, file);
        return this;
    }

    public Map<String, String> getParams() {
        return params;
    }

    public Map<String, String> getHeaders() {
        return headers;
    }

    public String getUrl() {
        return url;
    }

    public String getTag() {
        return tag;
    }

    public File getFile() {
        return file;
    }

    public Map<String, File> getFiles() {
        return files;
    }

    public BaseLoader build(){
//        return new OkHttpLoader(this);
        return new RetrofitLoader(this);
    }

}
